package gui.gui2d.eventsmanager;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Observable;

import utility.Color;
import utility.EventPass;
import utility.Point;

public class MouseListenerChess extends Observable implements MouseListener {
	private int dimensionSquare;
	public boolean attivo=true;
	Point pointPr;
	public MouseListenerChess(int dimensionSquare) {
		super();
		this.dimensionSquare = dimensionSquare;
	}
	@Override
	public void mouseClicked(MouseEvent e) {
		//System.out.println("move from ["+e.getPoint().x/dimensionSquare+","+e.getPoint().y/dimensionSquare+"]");
			//	Point point=new utility.Point(e.getPoint().y/dimensionSquare,e.getPoint().x/dimensionSquare);
			//	setChanged();
			//	notifyObservers(new EventPass(point));
	}
	@Override
	public void mouseEntered(MouseEvent e) {


	}
	@Override
	public void mouseExited(MouseEvent e) {

	}
	@Override
	public void mousePressed(MouseEvent e) {
		pointPr=new utility.Point((e.getPoint().y-25)/dimensionSquare,(e.getPoint().x-25)/dimensionSquare);
//		//System.out.println("move from ["+e.getPoint().x/dimensionSquare+","+e.getPoint().y/dimensionSquare+"]");
//		Point from=new utility.Point(e.getPoint().y/dimensionSquare,e.getPoint().x/dimensionSquare);
//		setChanged();
//		notifyObservers(new EventPass(from,EventPass.FROM));
	}
	@Override
	public void mouseReleased(MouseEvent e) {
		if(attivo){
			Point relese=new utility.Point((e.getPoint().y-25)/dimensionSquare,(e.getPoint().x-25)/dimensionSquare);
			if(relese.equals(pointPr)){
				Point point=new utility.Point((e.getPoint().y-25)/dimensionSquare,(e.getPoint().x-25)/dimensionSquare);
				setChanged();
				notifyObservers(new EventPass(point));
			}
		}
		
	}
	public void setEnable(boolean b) {
		attivo=b;
		
	}
	
//	@Override
//	public void mouseReleased(MouseEvent e) {
//		//System.out.println("move to ["+e.getPoint().x/dimensionSquare+","+e.getPoint().y/dimensionSquare+"]");
//		Point to=new utility.Point(e.getPoint().y/dimensionSquare,e.getPoint().x/dimensionSquare);
//		setChanged();
//		notifyObservers(new EventPass(to,EventPass.TO));
//
//		
//	}

}
